package com.sx.micowell.framework.adapter

import android.content.Context
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.example.mvvm.until.GlideApp
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter
import com.miloyu.modelnet.response.TrainListSettingInfo
import com.miloyu.modelnet.response.TrainSelectData
import com.miloyu.modelnet.response.getUrl
import com.sx.micowell.R
import com.sx.micowell.databinding.ItemTrainSettingBinding
import com.sx.micowell.framework.tools.DiffUtils

/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/9/1 13:56
 */
class TrainSettingAdapter(
    context: Context?,
    selectData: MutableList<TrainListSettingInfo>
) : SimpleDataBindingAdapter<TrainListSettingInfo, ItemTrainSettingBinding>(
    context,
    R.layout.item_train_setting,
    DiffUtils.getInstance().trainListSettingInfoItemCallback
) {
    var selectData: MutableList<TrainListSettingInfo>? = null

    init {
        this.selectData = selectData
    }

    override fun onBindItem(
        binding: ItemTrainSettingBinding,
        item: TrainListSettingInfo,
        holder: RecyclerView.ViewHolder?
    ) {
        item.categoryUrl?.let {
            var split = item.categoryUrl.split(",")
            if(split.size>0){
                GlideApp.with(mContext).load(item.categoryUrl.split(",")[0].getUrl()).into(binding.itemImage)
            }
        }
        binding.data = item
        binding.itemCheck.isChecked = selectData?.contains(item) == true

    }
}